package weather.com.weather.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import weather.com.weather.R
import weather.com.weather.bean.CityListBean

/**
 * Created by Administrator on 2018/6/5.
 */
class CityListAdapter(context: Context, listdata: List<CityListBean>) : BaseAdapter() {

    var listdatas: List<CityListBean> = listdata
    var contexts: Context = context

    open fun setdata(d:List<CityListBean>){
        listdatas = d
    }

    override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
        var v: View = LayoutInflater.from(contexts).inflate(R.layout.list_item, null)

        var city: TextView = v.findViewById(R.id.city_name)
        var temperature: TextView = v.findViewById(R.id.temperature)
        var weather: TextView = v.findViewById(R.id.weather)

        city.text = listdatas[p0].city
        temperature.text = listdatas[p0].temperature
        weather.text = listdatas[p0].weather

        return v
    }

    override fun getItem(p0: Int): Any {
        return listdatas[p0]
    }

    override fun getItemId(p0: Int): Long {
        return p0.toLong()
    }

    override fun getCount(): Int {
        if (listdatas == null) return 0

        return listdatas.size
    }
}